<template>
	<view class="page-wrap" :data-theme="theme" :class="theme" :style="globalColor.style">
		<HeadCustom :isSpace="false" :isBlur="isBlur" :isAppBtn="false" :isHome="!isApp"></HeadCustom>
		<view class="wrap" v-if="isLogin">
			<view class="bg-head">
				<view :style="{ height: statusBarHeight + 'px' }"></view>
				<view class="spaceHead"></view>
				<view class="management-hd">
					<view class="userInfo fboxRow Yend">
						<image class="avatar" :src="detail.companyLogo" mode="aspectFill"></image>
						<view class="fboxCol flex1 info">
							<view class="name font32 lh44">{{detail.companyName}}</view>
							<view class="completion lh34 font24 color-ACB4C7">{{detail.staffSize}} {{detail.industryName}}</view>
						</view>
						<view class="btn fboxRow Ycenter Xcenter border-radius12 font28"  @click="goPage('user')">切换到个人</view>
					</view>
					<view class="info-group fboxRow Ycenter">
						<view class="fboxCol Ycenter Xcenter flex1 action-item" v-for="(item, index) in infoList" :key="index" @click="goPage(item)">
							<!-- <view class="icon"><image src="https://ebc-prod.cdn.benwunet.com/uni-static/workplace/vita.png"></image></view> -->
							<view class="num font38 fwb color-E8CDA7">{{detail[item.key] || 0}}</view>
							<view class="tit font26 mt32 lh36 color-ACB4C7">{{item.tit}}</view>
						</view>
					</view>
				</view>
			</view>
			<view v-if="listConfig.loading == 'not-data'">
				<NotEmpty text="暂未发布职位，无法匹配人才" btn="发布职位" @btn="$pageTo('/recruit/enterprise/publishRecruitment?companyId='+companyId)" />
			</view>
			<view class="card-box" v-else>
				<view class="card-hd fboxRow Ycenter">
					<NavFilter type="company" :companyId="companyId" :reqData="reqData" :isMore="true" :isFilter="true" @change="tabsClick" />
				</view>
				<view class="card-bd">
					<view class="card-scroll" v-if="listData.length || listConfig.loading =='loading'">
						<vitaItem v-for="(item, index) in listData" :key="index" type="talent" :innerData="item" :jobId="jobId" />
						<u-loadmore fontSize="24rpx" :status="listConfig.loading" />
					</view>
					<view v-if="listConfig.loading == 'list-not'">
						<NotEmpty text="暂无相关人才" :height="300" />
					</view>
				</view>
			</view>
			<view style="height:100rpx"></view>
			<view class="fboxRow Ycenter Xcenter fixed-about">
				<!--  @click="$pageTo('/about/index?settingCode=HUMAN_RESOURCES_LICENSE')" -->
				<text class="font24 color-6B707C">(渝)人服证字[2023]号 第4000001313号</text>
			</view>
		</view>
		<not-login bottom="160rpx" ref="notLogin" />
	</view>
</template>

<script>
	import {resumeDataCount, companyDetail, resumePage} from '@/api/recruit.js';
	import { getRequest, unitNum } from '@/static/js/common.js';
	import { utf8to16, base64decode} from '@/static/js/Base64.js';
	import vitaItem from '../components/vita-item.vue';
	import NavFilter from '../components/nav-filter.vue';
	export default {
		components:{vitaItem, NavFilter},
		data() {
			return {
				theme: getApp().globalData.appTheme,
				globalColor: getApp().globalData.globalColor,
				infoList:[
					{key: 'publishJobCount',num: 12, icon:'https://ebc-prod.cdn.benwunet.com/uni-static/workplace/castJob.png', tit:'发布职位',path: '/recruit/enterprise/postPosition'},
					{key: 'receiveResumeCount',num: 12, icon:'https://ebc-prod.cdn.benwunet.com/uni-static/workplace/interview.png', tit:'收到简历',path: '/recruit/enterprise/resumeReceived'},
					{key: 'inviteCount',num: 12, icon:'https://ebc-prod.cdn.benwunet.com/uni-static/workplace/collect.png', tit:'邀约记录',path: '/recruit/enterprise/invitationRecord'},
					{key: 'collectResumeCount',num: 12, icon:'https://ebc-prod.cdn.benwunet.com/uni-static/workplace/collect.png', tit:'收藏简历',path: '/recruit/enterprise/collectedResume'},
				],
				detail:{},
				isApp: false,
				listConfig: {
					current: 1,
					size: 20,
					count: 0,
					loading: 'loading'
				},
				listData: [],
				companyId: getApp().globalData.companyId,
				reqData: {
					experienceList: [],
					educationList: [],
					expectCityId: '',
					age: '',
					ageMin: '',
					ageMax: '',
					gender: '',
					salary: '',
					salaryMin: '',
					salaryMax: '',
				},
				statusBarHeight: 0,
				isLogin: true,
				isBlur: false
			}
		},
		onLoad(option) {
			if(option && option.benwu){
				let benwu = utf8to16(base64decode(option.benwu))
				this.benwu = option.benwu
				const token = {
					access_token: getRequest(benwu,'token'),
					companyId: getRequest(benwu,'companyId'),
					statusBarHeight: getRequest(benwu,'statusBarHeight'),
					authStatus: getRequest(benwu,'authStatus'),
				}
				getApp().globalData.statusBarHeight = token.statusBarHeight
				getApp().globalData.companyId = token.companyId
				this.companyId = token.companyId
				uni.setStorageSync('bw_params', JSON.stringify(token));
				this.getDetail()
			}else if(option && option.companyId){
				this.companyId = option.companyId
				this.getDetail()
			}
			if(option && option.isApp){
				this.isApp = option.isApp == 1 ? true : false
			}else{
				const {bw_link} = getApp().getBWData(['bw_link'])
				this.isApp = bw_link.isApp == 1 ? true : false
			}
			const { bw_params } = getApp().getBWData(['bw_params']);
			this.statusBarHeight = getApp().globalData.statusBarHeight || bw_params.statusBarHeight;
			if (!getApp().globalData.statusBarHeight) {
				const sys = uni.getSystemInfoSync();
				this.statusBarHeight = sys.statusBarHeight;
			}
			// #ifdef MP
			// 根据胶囊按钮距离， 设置导航高度
			const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
			this.statusBarHeight = menuButtonInfo.top;
			// #endif
		},
		onShow() {
			// this.getInit()
			const filterTemp = getApp().globalData.filterTemp
			if(filterTemp.hasOwnProperty('expectCityId')){
				this.reqData = filterTemp
				this.reqData.educationList = filterTemp.educationList
				this.reqData.experienceList = filterTemp.experienceList
				this.reqData.salaryMin= filterTemp.salary && filterTemp.salary.split('-')[0]
				this.reqData.salaryMax= filterTemp.salary && filterTemp.salary.split('-')[1]
				this.reqData.ageMin= filterTemp.age && filterTemp.age.split('-')[0]
				this.reqData.ageMax= filterTemp.age && filterTemp.age.split('-')[1]
				this.reqData.cityId= filterTemp.expectCityId
				// this.getInit()
			}
		},
		onPageScroll(e) {
			if(e.scrollTop > 25){
				this.isBlur = true
			}else{
				this.isBlur = false
			}
		},
		methods: {
			getDetail(){
				companyDetail({id: this.companyId}).then(res=>{
					this.isLogin = true
					getApp().globalData.companyInfo = res.data
					getApp().globalData.companyId = res.data.companyId
					uni.setStorageSync('bw_company_info', JSON.stringify(res.data));
					this.detail = res.data
					this.getCount(this.companyId)
				}).catch(err=>{
					this.isLogin = false
					if(err.code == 401006){
						this.$refs.notLogin.openLogin({
							show: true,
							position: 'center'
						})
					}
				})
			},
			getCount(id){
				resumeDataCount({
					memberType: 2,
					countId: id
				}).then(res=>{
					this.detail = {
						...this.detail,
						...res.data
					}
				})
			},
			goPage(e){
				if(e == 'user'){
					this.$pageTo('/recruit/user/index')
				}else if(e.path == 'copy'){
					uni.setClipboardData({
						data: location.href,
						success: function () {
							console.log('success');
						}
					});
				}else{
					this.$pageTo(e.path)
				}
			},
			tabsClick(e){
				console.log(e)
				this.jobId = e.jobId == '全部' ? '': e.jobId
				this.positionType = e.positionType
				this.scrollTop = 0
				this.getInit()
			},
			getInit(){
				this.listConfig = {
					current: 1,
					size: 20,
					count: 0,
					loading: 'loading'
				}
				this.listData = []
				this.getList()
			},
			getList(){
				const { current, size, loading} = this.listConfig
				const pramas = this.jobId ? {current, size, jobId: this.jobId,
					companyId: this.companyId,
					...this.reqData
				} : {current, size, companyId: this.companyId,
					...this.reqData
				}
				resumePage(pramas).then(res=>{
					if(this.listData.length){
						this.listData = this.listData.concat(res.data.list) 
					}else{
						this.listData = res.data.list
					}
					if(res.data.total==0){
						this.listConfig.loading = 'list-not'
					}else{
						this.listConfig.loading = 'none'
					}
				}).catch(err=>{
					this.isLogin = false
					if(err.code == 401006){
						this.$refs.notLogin.openLogin({
							show: true,
							position: 'center'
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	// .wrap{padding: 112rpx 0 0;background: url('https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/bg3.png') no-repeat top center/contain;}
	
[data-theme='night-theme'] {
	.wrap{padding: 24rpx 0 0;background: url('https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/bg3.png') no-repeat top center/contain;}
}
[data-theme='lightBlue-theme'] {
	.bg-head{padding: 0;background: linear-gradient(180deg, var(--navViewStartColor) 0%, var(--navViewCenterColor) 32%, rgba(255,255,255,0) 100%);}
}
	
	.management-hd{padding: 24rpx 24rpx 0;}
	.management-hd .avatar{margin: 0 30rpx 0 0; width: 136rpx;height: 136rpx;overflow: hidden;border-radius: 12rpx;;}
	.management-hd .btn{width: 160rpx;height: 48rpx;}
	.management-hd .info{height: 136rpx;}
	.management-hd .btn{ color: var(--senderViewColor); background: var(--pureButtonBackOneColor); border: 1rpx solid var(--buttonOutlineOneColor);}
	
	.completion{margin-top: 18rpx;}
	
	
	.info-group{ padding: 50rpx 0 32rpx;}
	.action-item{position: relative;}
	.action-item::before{content: '';position: absolute;left: 0;top: 50%;margin-top: -24rpx;height: 48rpx;width: 1rpx; background-color:  rgba(255,255,255,0.08);}
	.action-item:first-child::before{display: none;}
	
	.card-scroll{padding:24rpx;}
	.fixed-about{position: absolute;bottom: 66rpx;left: 0;right: 0;}
	

</style>
